home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / signal / c / sigsuspend < prev    next >
Text File  |  1996-11-09  |  2KB  |  64 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/signal/c/RCS/sigsuspend,v $
  4.  * $Date: 1996/10/30 22:04:51 $
  5.  * $Revision: 1.1 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: sigsuspend,v $
  10.  * Revision 1.1  1996/10/30 22:04:51  unixlib
  11.  * Initial revision
  12.  *
  13.  ***************************************************************************/
  14.  
  15. static const char rcs_id[] = "$Id: sigsuspend,v 1.1 1996/10/30 22:04:51 unixlib Rel $";
  16.  
  17. /* Written by Nick Burrett, 26 Aug 1996.  */
  18.  
  19. #include <errno.h>
  20. #include <signal.h>
  21. #include <stddef.h>
  22. #include <unistd.h>
  23. #include <sys/unix.h>
  24.  
  25.  
  26. /* Change the set of blocked signals to SET,
  27.    wait until a signal arrives, and restore the set of blocked signals.  */
  28. int sigsuspend (const sigset_t *set)
  29. {
  30.   sigset_t oset;
  31.  
  32.   if (set == NULL)
  33.     {
  34.       errno = EINVAL;
  35.       return -1;
  36.     }
  37.  
  38.   if (sigprocmask(SIG_SETMASK, set, &oset) < 0)
  39.     return -1;
  40.  
  41.   /* Set the process sleeping.  Then wait until this is unset by something
  42.      else.  A process calling sigsuspend will usually be woken up after
  43.      delivery of a SIGSTOP signal or after any other signal and any pending
  44.      ones have been delivered.  */
  45.   __u->sleeping = 1;
  46.   /* Bit of a silly busy wait this is. But unfortunately we aren't under a
  47.      tasking system so it's not really possible to have a SWI Wimp_Poll
  48.      call here.  */
  49. #ifdef DEBUG
  50.   printf ("sigsuspend: Process suspended. Waiting for a signal.\n");
  51. #endif
  52.   while (__u->sleeping)
  53.     ;
  54. #ifdef DEBUG
  55.   printf ("sigsuspend: Signal received. Process continuing\n");
  56. #endif
  57.  
  58.   if (sigprocmask(SIG_SETMASK, &oset, (sigset_t *) NULL) < 0)
  59.     return -1;
  60.  
  61.   errno = EINTR;
  62.   return -1;
  63. }
  64.